<?php 
namespace app\superadmin\controller;
use think\Db;
use think\Controller;
class Videotype extends Base{
	public function index(){
		$types=Db::name('Videotype')->select();
		$this->assign('types',$types);
		return $this->fetch();
	}
	  //屏蔽/解除屏蔽
	public function shield($tid){
		$state=Db::name('videos')->where('tid',$tid)->where("vstatus='0'")->select();
		// dump(count($state));
		if (count($state)>0) {
			# code...
			$this->error("该类型下存在视频,无法封禁！");
		}else{

  $ustatenum=Db::name("videotype")->where("tid='$tid'")->value('tstatus');

  if($ustatenum==0){
    if (Db::name("videotype")->where("tid='$tid'")->update(['tstatus'=>1])) {
      $this->redirect('index');
    }else{
      $this->error('解除屏蔽失败');
    }

  }
  else{
    if (Db::name("videotype")->where("tid='$tid'")->update(['tstatus'=>0])) {
      $this->redirect('index');
    }else{
      $this->error('屏蔽失败');
    }    
  }
	}

	}
	public function addtypes(){
		$data=input('post.');
		// dump($data);
		$data+=['typedata'=>date('Y-m-d')
				];
		// dump($data);
		 $num=Db::name('videotype')->where('typename',$data['typename'])->count();
    if ($num>0) {
      # code...
      $this->error('视频类型重复，请重新添加！');
    }
		$res=Db::name('videotype')->insert($data);
		if ($res) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('视频类型添加失败！');
		}
	}
	public function update($tid){
		$data=Db::name('Videotype')->where('tid',$tid)->select();
		$this->assign('data',$data);
		return $this->fetch();
	}
	public function doupdate(){
		$data=input("post.");
		// dump($data);
		$res=Db::name('videotype')->where('tid',$data['tid'])->update(['typename'=>$data['typename']]);
		if ($res) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('修改失败！');
		}
	}
}
